<?php
namespace app\api\command;

use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\Db;

class CleanHot extends Command
{
    protected function configure()
    {
        $this->setName('cleanhot')->setDescription('clean room hot');
    }

    protected function execute(Input $input, Output $output)
    {
        /* 永不超时 */
        ini_set('max_execution_time', 0);
        $this->doCron();
    }


    public function doCron(){

        $cache = cache('command'.__CLASS__);
        if ($cache){
            echo 'running<br />';return false;
        }else{
            cache('command'.__CLASS__,true,1800);
        }

        $map['status'] = 1;
        Db::name('room')->field('room_id')->where($map)->chunk(1000,function ($items){
            foreach ($items as $k => $v){
                $hot = cache('hotVal'.$v['room_id']);
                if ($hot){
                    cache('hotVal'.$v['room_id'],null);
                }
            }
        });

        cache('command'.__CLASS__,null);

    }
}